<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/vue.js"></script>
    <script src="js/axios.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        #app {
            width: 80%;
            margin: 30px auto;
        }

        .item {
            float: left;
            width: 200px;
            height: 300px;
            border: 1px solid rosybrown;
            margin: 5px;
        }

        .item img {
            width: 200px;
            height: 200px;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="search">
            <div>类别：
                <input type="radio" value="" v-model="type" />全部
                <input type="radio" value="1" v-model="type" />服装
                <input type="radio" value="2" v-model="type" />鞋子
                <input type="radio" value="3" v-model="type" />箱包
                <input type="radio" value="4" v-model="type" />美妆
            </div>

        </div>
        <div class="table">
            <div class="item" v-for="item in  list">
                <img :src="item.goodsimg" />
                <p>{{item.goodsname}}</p>
                <p>商品价格{{item.goodsprice}} 商品数量{{item.goodsnum}}</p>
            </div>

        </div>

    </div>

</body>
<script>
    new Vue({
        el: "#app",
        data: {
            type: "",
            list: [],//商品列表
        },
        watch: {
            type() {//当type发生改变的时候 就触发
                //查询
                this.search();
            }
        },
        methods: {
            async search() {
                //有个bug  点全部的时候 type为 ""
                let params = {};
                if(this.type){
                    params.type = this.type;
                }

                let { data: list } =await axios({
                    method: "get", url: "http://localhost:2345/goodsinfos", params
                })
                //
                this.list = list;
            }
        },
        async created() {//页面加载的时候 请求所有数据
            let { data: list } = await axios({
                method: "get",
                url: "http://localhost:2345/goodsinfos",
                params: {
                }
            })
            this.list = list;
        }
    })

</script>

</html>